package com.apes.framework.query.lib;

import com.apestech.api.condition.ConditionExec;
import com.apestech.api.xml.esb.EsbUtil;
import com.apestech.framework.db.SqlSession;
import com.apestech.framework.dictionary.modul.Table;
import com.apestech.framework.json.JSONObject;
import com.apestech.framework.sql.callback.SqlCallback;
import com.apestech.framework.sql.modul.FromList;
import com.apestech.framework.util.DateUtil;
import com.apestech.framework.util.LocalVariable;
import com.apestech.framework.util.StringUtil;
import com.apestech.framework.xml.plugin.modul.SysCondition;

import java.util.ArrayList;
import java.util.Date;

public class JPAConditionSqlCallback extends StringUtil implements SqlCallback {

    private JSONObject json;
    private ConditionExec exec;
    private SysCondition sysCondition;
    private SqlSession session;

    public JPAConditionSqlCallback(JSONObject json, ConditionExec exec, SqlSession session) throws Exception {
        this.json=json;
        this.exec=exec;
        this.session=session;
        sysCondition= LocalVariable.getConfig().getSysCondition(session);
    }

    @Override
    public String getField(FromList fromtab, String fieldname) throws Exception {
        return null;
    }

    @Override
    public String getChildSelect(String key, String colName, String ftabName, Table ftab) throws Exception {
        return null;
    }

    @Override
    public JSONObject toJSON(FromList tables, JSONObject map) throws Exception {
        map=EsbUtil.getConData(map, session, sysCondition);
        JSONObject j=new JSONObject();
        j.put("ID", json.getString("CID"));
        j.put("NAME", json.getString("CNAME"));
        map.put("EXE_CONDITION", j);
        j=new JSONObject();
        j.put("ID", json.getString("MID"));
        j.put("NAME", json.getString("MNAME"));
        map.put("EXE_DIMENSION", j);
        return map;
    }

    @Override
    public String getFieldName(FromList tables, String field) throws Exception {
        return null;
    }
}
